<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>H+ 后台主题UI框架 - 空白页</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__STATIC__/layout/css/font-awesome.css?v=4.4.0" rel="stylesheet">
     <link href="__STATIC__/layout/css/plugins/summernote/summernote.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
     <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/plugins/webuploader/webuploader.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/demo/webuploader-demo.css">
    <!-- jqgrid-->
    <link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
     <link rel="stylesheet" href="__STATIC__/layout/css/channel.css" type="text/css">
     <style>
  .closeit{cursor:pointer;}
     </style>
</head>

<body style="color:#333;padding:3px;">
    <!-- 标题 -->
    <div class="page-heade">
        <h2 class="title_color text-center">市场费用补发票申请</h2>
    </div>
    <!-- 标题 -->
    <div class="contact-box" style="margin-bottom: 0;border-bottom: 0">
        <p>请输入供应商名称或输入供应商编号后在联想下拉框中选择供应商，然后点击确认提交按钮。</p>
    </div>
    <form class="form-inline">
    <div class="contact-box" style="margin-bottom: 0;border-bottom: 0">
        <div class="form-group">
              <table><tr><td>
                            <label for="" class="form-label">供应商编号：</label></td>
                               
                               <td> <div class="input-group" >
                                    <input type="text" placeholder="请输入关键字或空格查询" class="form-control gysno" name="gysno" value="">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div></td>
                             </tr></table>
            </div>
              <div class="form-group">
                        <table><tr><td>
                            <label for="" class="form-label">供应商名称：</label></td>
                               
                               <td> <div class="input-group" >
                                    <input type="text" placeholder="请输入关键字或空格查询" class="form-control gys" name="gys" value="">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div></td>
                             </tr></table>  
                </div>
             <div class="form-group">
                <table><tr><td>
                            <label for="" class="form-label">原申请文件编号：</label></td>
                               
                               <td> <div class="input-group" >
                                    <input type="text" placeholder="请输入关键字或空格查询" class="form-control ap" name="ap" value="">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div></td>
                             </tr></table>  
            </div>
    </div>
    </form>
    <form action="" method="post" style="display:none;" id="serform">
    <input type="hidden" name="gys" id="gys" value="{$gys}"/>
    <input type="hidden" name="aid" value="{$aid}" id="aid"/>
     <div class="contact-box" style="margin-bottom: 0;border-bottom: 1;">
       <span id="hasgys" style="display: none;">您选择的供应商是:
                  <span class="selectedOnlyOne " id="gysone" >
                                  
                    <span class="inin">{if $gys!=0}{$gy.gys_name}({$gy.no}){/if}</span>
                    <span class="closeit closegys">×</span>
                 </span>

        </span>
          <span id="hasap" style="display: none;">您选择的申请文件是:
                  <span class="selectedOnlyOne " id="apone" >
                                  
                    <span class="inin">{if $aid!=0}{$ap.no}{/if}</span>
                    <span class="closeit closeap">×</span>
                 </span>

        </span>
        <input type="submit" value="查找" class="btn btn-success"/>
    </div>
    </form>
    <form method="post" id="f1">
    <input type="hidden" name="state" id="state"/>
     {if $aid!=0||$gys!=0}
    <input type="hidden" name="gidn" value="{if $apply}{$apply.0.gid}{/if}"/>
    {/if}
     <table class="table row-margin-top table-bordered text-center bud_hei">
          <tr>
           <td colspan="13" class="text-left"><span class="colorRed">温馨提示：请在发票粘贴联上注明此申请单编号：201711170002</span><a href="javascript:;">点击查看图例</a></td>
          </tr>
          {if $aid!=0||$gys!=0}
            <tr class="info text-center">
            <th class="text-center" rowspan="2">序号</th>
            <th class="text-center"  rowspan="2"><input type="checkbox" id="qx"/></th>
            <th class="text-center" rowspan="2">核销明细编号</th>
            <th class="text-center" rowspan="2">原活动明细编号</th>
            <th class="text-center" rowspan="2">核销申请人</th>
            <th class="text-center" rowspan="2">供应商</th>
            <th class="text-center" rowspan="2">三级费用科目</th>
            <th class="text-center" rowspan="2">是否增值税</th>
            <th class="text-center" rowspan="2">税率</th>
              <th class="text-center" colspan="3">支付信息</th>
               <th class="text-center" rowspan="2">发票号<br><input type="button" value="批量设置" id="setFpNum" class="btn btn-info"/></th>
          </tr>
          <tr class="info text-center">
               <th class="text-center" >未税金额</th>
            <th class="text-center" >税金</th>
            <th class="text-center" >含税金额</th>
           </tr>
           {volist name="apply" id="vo"}
            <tr>
              <td>{$i}</td>
              <td><input type="checkbox" value="{$vo.heid}" class="dx" name="heid[]"/></td>
              <td><a onclick="hede({$vo.heid},{$vo.apid})">{$vo.ahpno}_{$vo.ahdno}</a></td>
              <td><a onclick="xiangqing({$vo.apid})">{$vo.apno}_{$vo.apdno}</a><a href="{:url('Apapply/mingxijuece')}?did={$vo.apdid}" title="决策依据" class="J_menuItem" ><span style="display: none;">决策依据</span><span class="glyphicon glyphicon-zoom-in fangda" aria-hidden="true" style="display: inline-block;"></span></a></td>
              <td>{$vo.em_name}</td>
              <td>{$vo.gys_name}</td>
              <td>{$vo.kemu}</td>

              <td>{if $vo.dikou==1}是{else/}否{/if}</td>
              <td><span class="num2 ObjectNum">{$vo.hexiao_shuilv}</span>%</td>
              <td class="num2 ObjectNum">{$vo.zfjine}</td> <td class="num2 ObjectNum">{$vo.shuijin}</td><td class="num2 ObjectNum">{$vo.hanshui}</td>
              <td><input type="text" class="form-control" name="fp_no[]"/></td>
            </tr>
           {/volist}
           {/if}
          <tr>
            <td colspan="2" >备注：</td>
            <td colspan="11">
                <textarea name="remark" id="" style="height: 80px;width: 60%;user-select:none;overflow-y: auto"></textarea><span>(500)</span>
            </td>
          </tr>
      </table>
      {if $aid!=0||$gys!=0}
          <div class="form-group white-bg" style="margin:20px 10px 20px 20px;">
            <div id="uploader" class="wu-example">
                <!--用来存放文件信息-->
                <div id="thelist" class="uploader-list">
                  
                </div>
                <div class="btns">
                    <div id="picker">选择文件</div>
                    <button id="ctlBtn" class="btn btn-default">开始上传</button>
                </div>
                <input type="hidden" name="attach" id="attach" >
            </div>
            <span>注：最多上传15个文件，每个文件小于50M,支持格式：</span><br>jpg,bnp,gif,png,jpeg,tif,raw,doc,docx,xls,xlsx,ppt,pptx,txt,pdf,rar,zip,mp4,avi,rmvb,rm,mid,3gp,AVI,3GP,,mpg,mp3,wma,wav
        </div>
      {/if}
      <div class="row text-center no-padding">
            {if $aid!=0||$gys!=0}
            <input type="button" class="btn btn-primary" onclick="tijiao(1)" value="保存为草稿"/>
            <input type="button" class="btn btn-warning" onclick="tijiao(3)" value="保存并提交流程"/>
            {/if}
            <button  class="btn btn-info" type="button" onclick="back()">返回</button>
        </div>
        <br/> <br/> <br/> <br/>
   </form>
    <div class="footer fixed_full text-center" id="fixBG">
        本次补发票未税金额合计：<strong class="colorRed"><span id="allweishui" class="num2 ObjectNum">0.00</span>元</strong>;税金合计：<strong class="colorRed"><span id="allshuijin" class="num2 ObjectNum">0.00</span>元</strong>;含税金额合计：<strong class="colorRed"><span id="allhanshui" class="num2 ObjectNum">0.00</span>元</strong>;实际金额合计：<strong class="colorRed"><span id="allhanshui2" class="num2 ObjectNum">0.00</span>元</strong>;
    </div>
    <!-- 全局js -->
    <script src="__STATIC__/layout/js/jquery.min.js?v=2.1.4"></script>
    <script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
    <script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>

    <script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
        <script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
         <script src="__STATIC__/layout/js/common.js"></script>
             <script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
             <script src="__STATIC__/layout/js/plugins/summernote/summernote.min.js"></script>
<script src="__STATIC__/layout/js/plugins/summernote/summernote-zh-CN.js"></script>

  <script src="__STATIC__/layout/js/contabs_sub.js"></script>
    <script>
           //详情也
function xiangqing(aid){
     var index = layer.open({
                            type:2,
                            title:'AP申请详情',
                            area:['100%','100%'],
                            maxmin:true,
                            content:'{:url("Apapply/apply_de")}?aid='+aid
                        })
}
     function hede(hid,aid){
    
      var index = layer.open({
                            type:2,
                            title:'AP申请详细',
                            area:['100%','100%'],
                            maxmin:true,
                            content:"{:url('Apapply/apCostVerifyDetail')}?hid="+hid+"&aid="+aid
                        })
    }
    function tijiao(state){
      var flag=0;var msg="";
        $(".dx").each(function(){
              if($(this).prop("checked")){
                flag=1;
                var fpno=$(this).parent().parent().children().eq(-1).children().val();
                if(fpno==""){
                  msg="选中的明细不能为空";
                  return false;
                }
              }
            })
        if(msg!=""){
          swal({
                    title: "错误",
                    text:  msg,
                    type: "warning"
                    });
          return;
        }
      if(flag==0){
         swal({
                    title: "错误",
                    text:  "至少选中一条明细",
                    type: "warning"
                    });
          return;
      }
      $("#state").val(state);
      gosubmit();
     
    }
    function gosubmit(){
       $(".dx").each(function(){
          if(!$(this).prop("checked")){
            $(this).parent().parent().remove();
          }
       })
       $.ajax({
                        cache: true,
                        type: "POST",
                        url:"{:url('newapply')}",
                        data:$('#f1').serialize(),// 你的formid
                        async: false,
                        error: function(requests) {
                            alert("Connection error");
                        },
                        success: function(datas) {
                        // alert(datas);
                          
                         var res1=JSON.parse(datas);
                          if(res1["state"]==1){
                            swal({
                            title: "完成",
                            text: "操作已成功",
                            type: "success"
                            },function(){
                              
                              location.href="{:url('apinapply2')}";
                            });

                                  }else{
                                    swal({
                            title: "错误",
                            text:  res1["msg"],
                            type: "warning"
                            });
                                  }
                          }
                    });
    }
    function back(){
      location.href="{:url('apinapply2')}";
    }
       /*批量设置发票号*/
        $("#setFpNum").click(function(){
          var flag=0;
            $(".dx").each(function(){
              if($(this).prop("checked")){
                flag=1;return false;
              }
            })
            if(flag==1){
                 var str = '<form  class="form-inline" style="margin:10px"><table class="table-bordered table"><tr><th class="info text-center" colspan="2">批量设置发票号</th></tr><tr><td style="min-width:120px;width:120px;" class="text-center">发票号<span class="colorRed">*</span>：</td><td><input type="text" id="tongyifph" class="form-control"/></td></tr></table> <div class="row sub_btn" style="width:100%;text-align:center;padding: 20px 0"><input type="button" class="btn btn-success" id="fphqd" value="确定"><input type="button" class="btn btn-warning" value="返回" id="cancelBack" style="margin-left:20px"></div></form>'
                  layer.open({
                    type: 1,
                    title:"",
                    skin: 'layui-layer-rim', //加上边框
                    area: ['500px', '300px'], //宽高
                    content: str
                  });
                    var cancelBack = document.getElementById('cancelBack')
                    cancelBack.onclick = function(){
                     layer.closeAll(); 
                     }
                      var fphqd = document.getElementById('fphqd')
                   fphqd.onclick = function(){
                    var neirong=$("#tongyifph").val();
                      $(".dx").each(function(){
                           if($(this).prop("checked")){
                             $(this).parent().parent().children().eq(-1).children().val(neirong);
                            }

                      })
                     layer.closeAll(); 
                     }
            }else{
              swal({
                    title: "错误",
                    text:  "至少选择一条明细",
                    type: "warning"
                    });
            }
           
        })
    function jisuan(){
      var weishui=0;var shuijin=0;var hanshui=0;
      $(".dx").each(function(){
        if($(this).prop("checked")){
          weishui+=parseFloat($(this).parent().parent().children().eq(9).html().replace(',', ''));
          shuijin+=parseFloat($(this).parent().parent().children().eq(10).html().replace(',', ''));
          hanshui+=parseFloat($(this).parent().parent().children().eq(11).html().replace(',', ''));
        }
      })
      $("#allweishui").html(weishui.toFixed(2));$("#allshuijin").html(shuijin.toFixed(2));$("#allhanshui").html(hanshui.toFixed(2));$("#allhanshui2").html(hanshui.toFixed(2));
         var $ObjectNum =$(".ObjectNum");
               toNum($ObjectNum);
    }
    $(".dx").change(function(){
      var flag=0;
      $(".dx").each(function(){
        if(!$(this).prop("checked")){
          flag=1;return false;
        }
      })
      if(flag==1){
        $("#qx").prop("checked",false);
      }else{
         $("#qx").prop("checked",true);
      }
      jisuan();
    })
    $("#qx").change(function(){
      if($(this).prop("checked")){
        $(".dx").prop("checked",true);
      }else{
         $(".dx").prop("checked",false);
      }
      jisuan();
    })
     $(".gys").bsSuggest({
        url: "{:url('gysjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
      $(this).val("")
       // $('#gysone>.inin').html(keyword.key)
       $.post('{:url("getgys")}',{id:keyword.id},function(re){
          if(re!=0){
            $('#gysone>.inin').html(re);
             $("#gys").val(keyword.id);
        
              $("#serform").show();
               $("#hasgys").show();
          }
       })
       

    });

    function isallhide(){
      if($("#gys").val()==0&&$("#aid").val()==0){
        $("#serform").hide();
      }else{
        $("#serform").show();
      }
      if($("#gys").val()==0)
        $("#hasgys").hide();
      else
        $("#hasgys").show();
      if($("#aid").val()==0)
        $("#hasap").hide();
      else
        $("#hasap").show();
    }
    $(".closegys").click(function(){
       $('#gysone>.inin').html("");
             $("#gys").val(0);
              $("#hasgys").hide();
              isallhide();
    })
     $(".closeap").click(function(){
       $('#apone>.inin').html("");
             $("#aid").val(0);
              $("#hasap").hide(); isallhide();
    })
  $(".gysno").bsSuggest({
        url: "{:url('gysnojson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "编号"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
      $(this).val("")
       // $('#gysone>.inin').html(keyword.key)
       $.post('{:url("getgys")}',{id:keyword.id},function(re){
          if(re!=0){
            $('#gysone>.inin').html(re);
             $("#gys").val(keyword.id);
        
              $("#serform").show();
              $("#hasgys").show();
          }
       })

    });

 $(".ap").bsSuggest({
        url: "{:url('apjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "申请单号"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
          $(this).val("")
            $('#apone>.inin').html(keyword.key);
             $("#aid").val(keyword.id);
        
              $("#serform").show();
              $("#hasap").show();
    });

    $(function(){
                $(".num2").each(function(){
        $(this).html(parseFloat($(this).html()).toFixed(2));
     })
         
         var $ObjectNum =$(".ObjectNum");
               toNum($ObjectNum);
      isallhide();
    })
    </script>
    <!-- Web Uploader -->
<script type="text/javascript">
    // 添加全局站点信息
    var BASE_URL = '__STATIC__/layout/js/plugins/webuploader';
</script>
<script src="__STATIC__/layout/js/plugins/webuploader/webuploader.min.js"></script>
<script type="text/javascript">
   // 文件上传
    jQuery(function() {
        var $ = jQuery,
            $list = $('#thelist'),
            $btn = $('#ctlBtn'),
            state = 'pending',
            uploader;

        var ids = [ ];
        uploader = WebUploader.create({

            // 不压缩image
            resize: false,

            // swf文件路径
            swf: BASE_URL + '/js/Uploader.swf',

            // 文件接收服务端。
            server: '{:url("upload/fileupload")}',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#picker'
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            $list.append( '<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">等待上传...</p>' +
                '</div>' );
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                    '</div>' +
                    '</div>').appendTo( $li ).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css( 'width', percentage * 100 + '%' );
        });

        uploader.on( 'uploadSuccess', function( file,response) {
            if(response.success)
                ids.push(response.id)
            $( '#'+file.id ).find('p.state').text(response.msg);
        });

        uploader.on( 'uploadError', function( file ) {
            $( '#'+file.id ).find('p.state').text('上传出错');
        });

        uploader.on( 'uploadComplete', function( file ) {
            $('#attach').val(ids.join(','))
            $( '#'+file.id ).find('.progress').fadeOut();
        });

        uploader.on( 'all', function( type ) {
            if ( type === 'startUpload' ) {
                state = 'uploading';
            } else if ( type === 'stopUpload' ) {
                state = 'paused';
            } else if ( type === 'uploadFinished' ) {
                state = 'done';
            }

            if ( state === 'uploading' ) {
                $btn.text('暂停上传');
            } else {
                $btn.text('开始上传');
            }
        });

        $btn.on( 'click', function() {
            if ( state === 'uploading' ) {
                uploader.stop();
            } else {
                uploader.upload();
            }
            return false
        });
     })
</script>
</body>
  
</html>
